import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import moment from 'dayjs'

export const columns: BasicColumn[] = [
  { title: '区域', dataIndex: 'departName', width: 70, align: 'left', },
  {title: '收付类型', dataIndex: 'sflx', width: 60,
    customRender:({text}) => {
      const color = text == '1' ? 'green' : 'blue';
      return render.renderTag(render.renderDict(text, 'sflxType'), color)
    }
  },
  {title: '收支项目', dataIndex:"pathName", align:"left", width: 180},
  {title: '收入金额', dataIndex: 'skje',  width: 70, align: 'right', className: 'text-green-500'},  
  {title: '支出金额', dataIndex: 'fkje',  width: 70, align: 'right', className: 'text-red-500'},
  {title: '收付日期', dataIndex: 'sfsj',  width: 90,},
  {title: '备注', dataIndex: 'bz',  width: 200, align: 'left',},
  {title: '操作人', dataIndex: 'updateName',  width: 60,},
  {title: '操作日期', dataIndex: 'updateTime',  width: 100, format: "date|YYYY-MM-DD hh:mm"},
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '收付类型',
    field: 'sflx',
    component: 'Input',
    componentProps: {
      placeholder: ' '
    }
  },
  {
    label: '收支项目',
    field: 'fklx',
    component: 'Input',
    componentProps: {
      placeholder: ' '
    }
  },
];

export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  { label: "", field: "coopId", component: "Input", show: false },
  {
    label: '部门',
    field: 'region',
    component: 'Select',
    colProps: { span: 20 },
    rules: [{required: true,  message: '请选择部门'}],
  },
  {
    label: '收付类型',
    field: 'sflx',
    component: 'JDictSelectTag',
    defaultValue: '2',
    colProps: { span: 20 },
    rules: [{required: true, type: 'string', message: '请选择收支类型'}],
    componentProps: () => {
      return {
        dictCode: 'sflxType',
        placeholder: ' ',
        showChooseOption: false,
      }
    }
  },
  {
    label: '收支项目',
    field: 'cId',
    component: 'Cascader',
    colProps: { span: 20 },
    componentProps: {
      getPopupContainer: () => document.body,
      //stringToNumber: true
    },
    dynamicRules: ({ model }) => {
      return [
        { required: true, message: '收支项目不能为空！' },
        { validator: (_, value) => {
            //console.info("dynamicRules", value, typeof value == 'undefined')
            return new Promise((resolve, reject) => {
              if (value == '' || typeof value == 'undefined') {
                return resolve() //不与required重复
              } else if ( value.length == 3) {
                model.coopId = value[2]
                return resolve()
              } else {
                model.coopId = ''
                return reject('选择的项目不对请重新选择！');
              }
            });
          },
        },
      ]
    },
  },
  {
    label: '收支金额',
    field: 'je',
    component: 'InputNumber',
    rules: [{required: true, type: 'number'}],
    colProps: {
      span: 20,
    },
  },
  {
    label: '收付时间',
    field: 'sfsj',
    component: 'DatePicker',
    defaultValue: moment().format('YYYY-MM-DD'),
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
    colProps: {
      span: 20,
    },
  },
  {
    label: '备注',
    field: 'bz',
    component: 'InputTextArea',
    componentProps: {
      placeholder: ' ',
      rows: 8,
    },
    colProps: {
      span: 20,
    },
  },
];
